package com.tianfei.crowd.controller;

import com.tianfei.crowd.entity.vo.DetailProjectVO;
import com.tianfei.crowd.entity.vo.PortalTypeVO;
import com.tianfei.crowd.entity.vo.ProjectVO;
import com.tianfei.crowd.service.api.ProjectService;
import com.tianfei.crowd.utils.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * MySQL端本地的 controller：提供给 project微服务远程调用 的 controller
 *
 * @author: Herz
 * @date: 2021/8/3 19:41
 */
@RestController
public class ProjectProviderController {

    @Autowired
    private ProjectService projectService;



    @RequestMapping("/get/project/detail/remote/{projectId}")
    public ResultEntity<DetailProjectVO> getDetailProjectVORemote(@PathVariable("projectId") Integer projectId){

        try {
            DetailProjectVO detailProjectVO = projectService.getDetailProjectVO(projectId);

            return ResultEntity.successWithData(detailProjectVO);
        } catch (Exception e) {
            e.printStackTrace();

            return ResultEntity.failed(e.getMessage());
        }
    }



    @RequestMapping("/get/portal/type/project/data/remote")
    public ResultEntity<List<PortalTypeVO>> getPortalTypeVODataRemote(){

        try {
            List<PortalTypeVO> portalTypeVOList = projectService.getPortalTypeVOList();

            return ResultEntity.successWithData(portalTypeVOList);

        } catch (Exception e) {
            e.printStackTrace();

            return ResultEntity.failed(e.getMessage());
        }
    }



    @RequestMapping("/save/project/vo/remote")
    public ResultEntity<String> saveProjectRemote(
            @RequestBody ProjectVO projectVO,
            @RequestParam("memberId") Integer memberId) {

        try {
            projectService.saveProject(projectVO, memberId);

            return ResultEntity.successWithOutData();
        } catch (Exception e) {
            e.printStackTrace();

            return ResultEntity.failed(e.getMessage());
        }
    }
}
